NTP Clock

Lately, I’ve been working a lot on improving the live streaming equipment we have at my school. One of the problems we were having, was that we didn’t really have a good time indication. We had been usingthis appon a phone, but that meant one of us couldn’t use their phone and we also didn’t really have a good place to mount it.


I started by building a prototype, I decided that for me the best way to get accurate time would be theNTP protocolas we already had a good network set up and I had an Arduino Ethernet shield lying around. I also decided to throw in anRTC (Real Time Clock)to enable me to keep accurate time without an ethernet connection. This was because our network switch takes a couple minutes to start up, and because I had heard stories about the NTP protocol being very slow. I was afraid it would take too long to get the time. This ended up not being a problem and an RTC wouldn’t have been necessary.

As a way to show the time I went for a1.8-inch display based on the ST7735as I already had them lying around for a different project. They are made to be used in portrait mode so they have terrible viewing angles if you look at it from a high angle. As I used it in landscape mode, this meant that it’s way less see-able from the left.

Optimizing the code for this project was easily the hardest part. In the beginning, I was using adisplay library by Adafruit,which was very slow, forcing me to optimize the living s**** out of the functions that update the display, as writing the display would take more than a second making the clock skip seconds. I switched to alibrary for the ST7735 by Bodmer,which ended up being way faster and resolved much of my problems. Then I started implementing the NTP library, which caused even more problems. First I had to set up code that tried connecting to the internet at bootup, with visual feedback, and then I made it possible to update time (or connect to the internet) while the device is already running. I also added an indication for when the device has been connected to the internet, and when for when an NTP has been sent.

One of the things I struggled with is getting accurate time. Every time I’d receive an NTP package and update the time, it would be off from 0-1 second. I later found out that it was because I was writing the seconds to the RTC, but not fractions of seconds. As the RTC doesn’t support milliseconds, I resolved this by setting a variable to the time plus one second and wait till the remainder of the second has passed (1000 milliseconds – passed milliseconds) and then write the time to the RTC.A better explanation can be found here.

When I was about halfway with the code, I started building an enclosure. I designed it to fit in a1u rack mount.I planned to laser cut the square part of the enclosure, but here in the Netherlands another lockdown happened and I wouldn’t be able to access the cutter for some time. As the deadline I had for this project was nearby, I decided to print it and it actually turned out quite nice.

All in all this project was quite successful and I’m happy with the results. In the future, I will add stopwatch functionality, as I’ve already added the buttons anyway, and I might add OSC implementation. OSC capability would mean you could start timers, stopwatches, and even display messages on the display over the network. All code is available onGithuband the STL’s are downloadable onThingiverse. If you are interested in building this and need help, feel free tocontact me.